import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {api} from "@core/service/config/api";
import {BBYUtils} from "@shared/utils/BBYUtils";
import {Result} from "@shared/models/Result";
import {Favorite, FavoriteGroup, UserGroup} from "@shared/models/UserInfo";
import {UserSettings} from "@shared/models/UserSettings";
export interface FavoriteActionReq {
  // 干啥，有：addFav,addGroup,deleteFav,deleteGroup,renameFav,renameGroup，必须
  opera:'addFav'|'addGroup'|'deleteFav'|'deleteGroup'|'renameFav'|'renameGroup'
  // 重命名、收藏分组id，必须
  groupId?:string
  // 重命名时必须
  newName?:string
  // 重命名、删除收藏必须
  fileId?:string
}
export interface UserGroupActionReq {
   // 干啥，有：addUser,addGroup,deleteUser,deleteGroup,renameGroup，必须
  opera:'addUser'|'addGroup'|'deleteUser'|'deleteGroup'|'renameGroup'
   // 分组id，必须
  groupId?:string
  // 重命名时必须
  newName?:string
  // 添加、删除用户必须
  userId?:string
}
@Injectable({
  providedIn: 'root',
})
export class UserActionService {
  constructor(private http: HttpClient) {
  }

  getFavorites() {
    return this.http.get<Result>(api.favorites, BBYUtils.createHeadersOption())
  }

  setFavorites(data: FavoriteActionReq) {
    return this.http.post<Result>(api.favorites, data, BBYUtils.createHeadersOption())
  }

  getUserGroups() {
    return this.http.get<Result>(api.userGroups, BBYUtils.createHeadersOption())
  }
  setUserGroups(option: UserGroupActionReq) {
    return this.http.post<Result>(api.userGroups, option, BBYUtils.createHeadersOption())
  }
  getSettings() {
    return this.http.get<Result>(api.settings, BBYUtils.createHeadersOption())
  }
  saveSettings(option: UserSettings) {
    return this.http.post<Result>(api.settings, option, BBYUtils.createHeadersOption())
  }
  searchUser(regex:string,page:number=1){
    return this.http.get<Result>(`${api.searchUser}?regex=${regex}&page=${page}`, BBYUtils.createHeadersOption())
  }

  getUserPubInfo(userId:string) {
    return this.http.get<Result>(`${api.pubInfo}/${userId}`)
  }

}
